{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.054821Z",
     "start_time": "2020-08-22T21:56:47.809789Z"
    }
   },
   "outputs": [],
   "source": [
    "# Import packages\n",
    "import os\n",
    "import sys\n",
    "import datetime\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import yfinance as yf\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Data Exploration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.058894Z",
     "start_time": "2020-08-22T21:56:48.055783Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(datetime.date(2010, 1, 1), datetime.date(2020, 8, 23))"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Set date timestamps for historical data download\n",
    "start_date = datetime.datetime(2010, 1, 1).date()\n",
    "end_date = datetime.datetime.now().date()\n",
    "start_date, end_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.074261Z",
     "start_time": "2020-08-22T21:56:48.059783Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.timedelta(days=3887)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "end_date - start_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.078489Z",
     "start_time": "2020-08-22T21:56:48.075772Z"
    }
   },
   "outputs": [],
   "source": [
    "ticker = \"GOOGL\"\n",
    "# ticker = \"MSFT\"\n",
    "# ticker = \"FB\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.089737Z",
     "start_time": "2020-08-22T21:56:48.079763Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "yfinance.Ticker object <GOOGL>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "msft = yf.Ticker(ticker)\n",
    "\n",
    "msft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.485442Z",
     "start_time": "2020-08-22T21:56:48.090730Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2679, 8)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_data = msft.history(start=start_date, end=end_date, interval=\"1d\").reset_index()\n",
    "\n",
    "historical_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.492781Z",
     "start_time": "2020-08-22T21:56:48.486315Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2009-12-31</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>310.30</td>\n",
       "      <td>2437100</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>313.69</td>\n",
       "      <td>3908400</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-05</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>312.31</td>\n",
       "      <td>6003300</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-06</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>304.43</td>\n",
       "      <td>7949400</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-07</td>\n",
       "      <td>305.01</td>\n",
       "      <td>305.31</td>\n",
       "      <td>296.62</td>\n",
       "      <td>297.35</td>\n",
       "      <td>12815700</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date    Open    High     Low   Close    Volume  Dividends  \\\n",
       "0 2009-12-31  312.69  313.01  310.30  310.30   2437100          0   \n",
       "1 2010-01-04  313.79  315.07  312.43  313.69   3908400          0   \n",
       "2 2010-01-05  313.90  314.23  311.08  312.31   6003300          0   \n",
       "3 2010-01-06  313.24  313.24  303.48  304.43   7949400          0   \n",
       "4 2010-01-07  305.01  305.31  296.62  297.35  12815700          0   \n",
       "\n",
       "   Stock Splits  \n",
       "0           0.0  \n",
       "1           0.0  \n",
       "2           0.0  \n",
       "3           0.0  \n",
       "4           0.0  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above data shows stock prices on per day basis.\n",
    "\n",
    "+ High: Max stock price on that particular day\n",
    "+ Low: Lowest price went on that particular day\n",
    "+ Open: Stock price opening on that particular day\n",
    "+ Close: Final closing price of the stock on that particular day\n",
    "+ Volume: Amount of stock traded on that day\n",
    "+ Dividends: Dividens given (if any)\n",
    "+ Stock Splits: Stock split happend on that particular day (if any)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.516293Z",
     "start_time": "2020-08-22T21:56:48.494046Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>2679.000000</td>\n",
       "      <td>2679.000000</td>\n",
       "      <td>2679.000000</td>\n",
       "      <td>2679.000000</td>\n",
       "      <td>2.679000e+03</td>\n",
       "      <td>2679.0</td>\n",
       "      <td>2679.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>696.466558</td>\n",
       "      <td>702.655006</td>\n",
       "      <td>689.932647</td>\n",
       "      <td>696.549194</td>\n",
       "      <td>3.311138e+06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>364.876703</td>\n",
       "      <td>368.678913</td>\n",
       "      <td>361.285533</td>\n",
       "      <td>365.290921</td>\n",
       "      <td>2.626416e+06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.038602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>219.370000</td>\n",
       "      <td>221.360000</td>\n",
       "      <td>217.030000</td>\n",
       "      <td>218.250000</td>\n",
       "      <td>5.206000e+05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>332.840000</td>\n",
       "      <td>335.770000</td>\n",
       "      <td>330.240000</td>\n",
       "      <td>334.210000</td>\n",
       "      <td>1.545400e+06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>591.730000</td>\n",
       "      <td>595.300000</td>\n",
       "      <td>587.450000</td>\n",
       "      <td>591.970000</td>\n",
       "      <td>2.387600e+06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1036.195000</td>\n",
       "      <td>1050.525000</td>\n",
       "      <td>1023.580000</td>\n",
       "      <td>1036.455000</td>\n",
       "      <td>4.352950e+06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1585.030000</td>\n",
       "      <td>1591.880000</td>\n",
       "      <td>1562.310000</td>\n",
       "      <td>1576.250000</td>\n",
       "      <td>2.961990e+07</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.998000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Open         High          Low        Close        Volume  \\\n",
       "count  2679.000000  2679.000000  2679.000000  2679.000000  2.679000e+03   \n",
       "mean    696.466558   702.655006   689.932647   696.549194  3.311138e+06   \n",
       "std     364.876703   368.678913   361.285533   365.290921  2.626416e+06   \n",
       "min     219.370000   221.360000   217.030000   218.250000  5.206000e+05   \n",
       "25%     332.840000   335.770000   330.240000   334.210000  1.545400e+06   \n",
       "50%     591.730000   595.300000   587.450000   591.970000  2.387600e+06   \n",
       "75%    1036.195000  1050.525000  1023.580000  1036.455000  4.352950e+06   \n",
       "max    1585.030000  1591.880000  1562.310000  1576.250000  2.961990e+07   \n",
       "\n",
       "       Dividends  Stock Splits  \n",
       "count     2679.0   2679.000000  \n",
       "mean         0.0      0.000746  \n",
       "std          0.0      0.038602  \n",
       "min          0.0      0.000000  \n",
       "25%          0.0      0.000000  \n",
       "50%          0.0      0.000000  \n",
       "75%          0.0      0.000000  \n",
       "max          0.0      1.998000  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.613917Z",
     "start_time": "2020-08-22T21:56:48.517910Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7fbd8074e610>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAAO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hojCkyxuzDkYl2JEH8b9kYk22M+dbaPg24L5caEr/HCq6xPI3i9xiKQT/UlmU0wDIR2SQiM6yyUFySsrrX1Fiv9W5reGOBc+iDRn6NUrvlUhvjNUIj/j2GYtAPNRcYY4YDlwF3ichY94PG8b0ypObdhuI1WV4BegBDgWzg+QZtTQBIgJdLDUZ+rrFR/x5DMehXaVnGxsIYc9D68yjwEY6virVakjJIVfeaGt21GmOOGGNsxhg78BqO3yU00muUwCyX2uiusbH/HkMx6G8EeolINxGJAqbiWKqx0RGROBFJcG4DE4FthOaSlNW9ps+AiSLS0vp6PdEqC1pe91d+guN3CY5rnCoi0SLSDegFbCCI/y2LBGy51KD9PZZ3jY3+99hQd5Dr8gfHTIE9OO6YP9rQ7anFdXTHcad/M7DdeS1Aa2AlsBdYAbSyygV42brurUBqQ19DOdf1Ho6vxSU4xjdvq8k1Ab/AcbMsHbi1oa+rCtf4D+satuD4T9/Brf6j1jXuBi4L9n/LwAU4hm62AN9bP5ND6fdYwTU26t+jpmFQSqkmJBSHd5RSSpVDg75SSjUhGvSVUqoJ0aCvlFJNiAZ9pZRqQjToK6VUE6JBXymlmpD/B7z8NPByzMlKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "\n",
    "plt.plot(historical_data.Close)\n",
    "\n",
    "plt.legend([\"Close\", \"Open\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Feature Engineering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.620804Z",
     "start_time": "2020-08-22T21:56:48.614681Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2009-12-31</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>310.30</td>\n",
       "      <td>2437100</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>313.69</td>\n",
       "      <td>3908400</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-05</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>312.31</td>\n",
       "      <td>6003300</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-06</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>304.43</td>\n",
       "      <td>7949400</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-07</td>\n",
       "      <td>305.01</td>\n",
       "      <td>305.31</td>\n",
       "      <td>296.62</td>\n",
       "      <td>297.35</td>\n",
       "      <td>12815700</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date    Open    High     Low   Close    Volume  Dividends  \\\n",
       "0 2009-12-31  312.69  313.01  310.30  310.30   2437100          0   \n",
       "1 2010-01-04  313.79  315.07  312.43  313.69   3908400          0   \n",
       "2 2010-01-05  313.90  314.23  311.08  312.31   6003300          0   \n",
       "3 2010-01-06  313.24  313.24  303.48  304.43   7949400          0   \n",
       "4 2010-01-07  305.01  305.31  296.62  297.35  12815700          0   \n",
       "\n",
       "   Stock Splits  \n",
       "0           0.0  \n",
       "1           0.0  \n",
       "2           0.0  \n",
       "3           0.0  \n",
       "4           0.0  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.629828Z",
     "start_time": "2020-08-22T21:56:48.621503Z"
    }
   },
   "outputs": [],
   "source": [
    "historical_data.drop(\n",
    "    columns=[\"Dividends\", \"Stock Splits\", \"Volume\"], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.645702Z",
     "start_time": "2020-08-22T21:56:48.631111Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Present date: 2020-08-21 00:00:00\n",
      "Next valid date: 2020-08-24 00:00:00\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-08-24</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date  Open  High  Low  Close\n",
       "0 2020-08-24   0.0   0.0  0.0    0.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add placeholder for forecast\n",
    "present_date = historical_data.Date.max()\n",
    "day_number = pd.to_datetime(present_date).isoweekday()\n",
    "\n",
    "if day_number in [5, 6]:\n",
    "    next_date = present_date + datetime.timedelta(days=(7-day_number) + 1)\n",
    "else:\n",
    "    next_date = present_date + datetime.timedelta(days=1)\n",
    "print(\"Present date:\", present_date)\n",
    "print(\"Next valid date:\", next_date)\n",
    "\n",
    "test_row = pd.DataFrame([[next_date, 0.0, 0.0, 0.0, 0.0]], columns=historical_data.columns)\n",
    "test_row.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.651300Z",
     "start_time": "2020-08-22T21:56:48.646631Z"
    }
   },
   "outputs": [],
   "source": [
    "historical_data = pd.concat([historical_data, test_row])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.676997Z",
     "start_time": "2020-08-22T21:56:48.652003Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Close_lag_1</th>\n",
       "      <th>Open_lag_1</th>\n",
       "      <th>High_lag_1</th>\n",
       "      <th>Low_lag_1</th>\n",
       "      <th>Close_lag_2</th>\n",
       "      <th>...</th>\n",
       "      <th>High_lag_4</th>\n",
       "      <th>Low_lag_4</th>\n",
       "      <th>Close_lag_5</th>\n",
       "      <th>Open_lag_5</th>\n",
       "      <th>High_lag_5</th>\n",
       "      <th>Low_lag_5</th>\n",
       "      <th>Close_lag_6</th>\n",
       "      <th>Open_lag_6</th>\n",
       "      <th>High_lag_6</th>\n",
       "      <th>Low_lag_6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2009-12-31</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>310.30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>313.69</td>\n",
       "      <td>310.30</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-05</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>312.31</td>\n",
       "      <td>313.69</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>310.30</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-06</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>304.43</td>\n",
       "      <td>312.31</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>313.69</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-07</td>\n",
       "      <td>305.01</td>\n",
       "      <td>305.31</td>\n",
       "      <td>296.62</td>\n",
       "      <td>297.35</td>\n",
       "      <td>304.43</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>312.31</td>\n",
       "      <td>...</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date    Open    High     Low   Close  Close_lag_1  Open_lag_1  \\\n",
       "0 2009-12-31  312.69  313.01  310.30  310.30          NaN         NaN   \n",
       "1 2010-01-04  313.79  315.07  312.43  313.69       310.30      312.69   \n",
       "2 2010-01-05  313.90  314.23  311.08  312.31       313.69      313.79   \n",
       "3 2010-01-06  313.24  313.24  303.48  304.43       312.31      313.90   \n",
       "4 2010-01-07  305.01  305.31  296.62  297.35       304.43      313.24   \n",
       "\n",
       "   High_lag_1  Low_lag_1  Close_lag_2  ...  High_lag_4  Low_lag_4  \\\n",
       "0         NaN        NaN          NaN  ...         NaN        NaN   \n",
       "1      313.01     310.30          NaN  ...         NaN        NaN   \n",
       "2      315.07     312.43       310.30  ...         NaN        NaN   \n",
       "3      314.23     311.08       313.69  ...         NaN        NaN   \n",
       "4      313.24     303.48       312.31  ...      313.01      310.3   \n",
       "\n",
       "   Close_lag_5  Open_lag_5  High_lag_5  Low_lag_5  Close_lag_6  Open_lag_6  \\\n",
       "0          NaN         NaN         NaN        NaN          NaN         NaN   \n",
       "1          NaN         NaN         NaN        NaN          NaN         NaN   \n",
       "2          NaN         NaN         NaN        NaN          NaN         NaN   \n",
       "3          NaN         NaN         NaN        NaN          NaN         NaN   \n",
       "4          NaN         NaN         NaN        NaN          NaN         NaN   \n",
       "\n",
       "   High_lag_6  Low_lag_6  \n",
       "0         NaN        NaN  \n",
       "1         NaN        NaN  \n",
       "2         NaN        NaN  \n",
       "3         NaN        NaN  \n",
       "4         NaN        NaN  \n",
       "\n",
       "[5 rows x 29 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create lag features\n",
    "for i in range(1, 7):\n",
    "    historical_data[f\"Close_lag_{i}\"] = historical_data.Close.shift(periods=i, axis=0)\n",
    "    historical_data[f\"Open_lag_{i}\"] = historical_data.Open.shift(periods=i, axis=0)\n",
    "    historical_data[f\"High_lag_{i}\"] = historical_data.High.shift(periods=i, axis=0)\n",
    "    historical_data[f\"Low_lag_{i}\"] = historical_data.Low.shift(periods=i, axis=0)\n",
    "\n",
    "historical_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.692390Z",
     "start_time": "2020-08-22T21:56:48.677732Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Close_lag_1</th>\n",
       "      <th>Open_lag_1</th>\n",
       "      <th>High_lag_1</th>\n",
       "      <th>Low_lag_1</th>\n",
       "      <th>Close_lag_2</th>\n",
       "      <th>...</th>\n",
       "      <th>High_lag_4</th>\n",
       "      <th>Low_lag_4</th>\n",
       "      <th>Close_lag_5</th>\n",
       "      <th>Open_lag_5</th>\n",
       "      <th>High_lag_5</th>\n",
       "      <th>Low_lag_5</th>\n",
       "      <th>Close_lag_6</th>\n",
       "      <th>Open_lag_6</th>\n",
       "      <th>High_lag_6</th>\n",
       "      <th>Low_lag_6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2009-12-31</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>310.30</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>313.69</td>\n",
       "      <td>310.30</td>\n",
       "      <td>312.69</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.30</td>\n",
       "      <td>0.00</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-05</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>312.31</td>\n",
       "      <td>313.69</td>\n",
       "      <td>313.79</td>\n",
       "      <td>315.07</td>\n",
       "      <td>312.43</td>\n",
       "      <td>310.30</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-06</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>304.43</td>\n",
       "      <td>312.31</td>\n",
       "      <td>313.90</td>\n",
       "      <td>314.23</td>\n",
       "      <td>311.08</td>\n",
       "      <td>313.69</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-07</td>\n",
       "      <td>305.01</td>\n",
       "      <td>305.31</td>\n",
       "      <td>296.62</td>\n",
       "      <td>297.35</td>\n",
       "      <td>304.43</td>\n",
       "      <td>313.24</td>\n",
       "      <td>313.24</td>\n",
       "      <td>303.48</td>\n",
       "      <td>312.31</td>\n",
       "      <td>...</td>\n",
       "      <td>313.01</td>\n",
       "      <td>310.3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date    Open    High     Low   Close  Close_lag_1  Open_lag_1  \\\n",
       "0 2009-12-31  312.69  313.01  310.30  310.30         0.00        0.00   \n",
       "1 2010-01-04  313.79  315.07  312.43  313.69       310.30      312.69   \n",
       "2 2010-01-05  313.90  314.23  311.08  312.31       313.69      313.79   \n",
       "3 2010-01-06  313.24  313.24  303.48  304.43       312.31      313.90   \n",
       "4 2010-01-07  305.01  305.31  296.62  297.35       304.43      313.24   \n",
       "\n",
       "   High_lag_1  Low_lag_1  Close_lag_2  ...  High_lag_4  Low_lag_4  \\\n",
       "0        0.00       0.00         0.00  ...        0.00        0.0   \n",
       "1      313.01     310.30         0.00  ...        0.00        0.0   \n",
       "2      315.07     312.43       310.30  ...        0.00        0.0   \n",
       "3      314.23     311.08       313.69  ...        0.00        0.0   \n",
       "4      313.24     303.48       312.31  ...      313.01      310.3   \n",
       "\n",
       "   Close_lag_5  Open_lag_5  High_lag_5  Low_lag_5  Close_lag_6  Open_lag_6  \\\n",
       "0          0.0         0.0         0.0        0.0          0.0         0.0   \n",
       "1          0.0         0.0         0.0        0.0          0.0         0.0   \n",
       "2          0.0         0.0         0.0        0.0          0.0         0.0   \n",
       "3          0.0         0.0         0.0        0.0          0.0         0.0   \n",
       "4          0.0         0.0         0.0        0.0          0.0         0.0   \n",
       "\n",
       "   High_lag_6  Low_lag_6  \n",
       "0         0.0        0.0  \n",
       "1         0.0        0.0  \n",
       "2         0.0        0.0  \n",
       "3         0.0        0.0  \n",
       "4         0.0        0.0  \n",
       "\n",
       "[5 rows x 29 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_data.fillna(0, inplace=True)\n",
    "historical_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.696262Z",
     "start_time": "2020-08-22T21:56:48.693151Z"
    }
   },
   "outputs": [],
   "source": [
    "historical_data.drop(\n",
    "    columns=[\"Open\", \"High\", \"Low\"], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.700093Z",
     "start_time": "2020-08-22T21:56:48.697436Z"
    }
   },
   "outputs": [],
   "source": [
    "# # Create a holiday dataframe\n",
    "# min_date, max_date = historical_data.Date.min(), historical_data.Date.max()\n",
    "# print(\"Min/Max dates:\", min_date, max_date)\n",
    "\n",
    "# date_range = pd.date_range(start=min_date, end=max_date)\n",
    "# print(\"Date range:\", date_range.min(), date_range.max())\n",
    "\n",
    "# # Find dates not present in historical df - closed stock market holiday\n",
    "# holiday_date_range = [d.date() for d in date_range if d not in historical_data.Date]\n",
    "# holiday_date_range[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.704810Z",
     "start_time": "2020-08-22T21:56:48.700962Z"
    }
   },
   "outputs": [],
   "source": [
    "# holidays = pd.DataFrame({\n",
    "#     \"holiday\": \"shutdown\",\n",
    "#     \"ds\": pd.to_datetime(holiday_date_range),\n",
    "#     \"lower_bound\": 0,\n",
    "#     \"upper_bound\": 1,\n",
    "# })\n",
    "\n",
    "# holidays.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Modelling"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Facebook's Prophet: Single Timestep Forecasting\n",
    "\n",
    "References: \n",
    "+ https://facebook.github.io/prophet/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.809310Z",
     "start_time": "2020-08-22T21:56:48.705606Z"
    }
   },
   "outputs": [],
   "source": [
    "import s as prophet"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Train and Forecast"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:48.812225Z",
     "start_time": "2020-08-22T21:56:48.810206Z"
    }
   },
   "outputs": [],
   "source": [
    "lag_features = [col for col in historical_data.columns if \"lag\" in col]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:52.200474Z",
     "start_time": "2020-08-22T21:56:48.813106Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<fbprophet.forecaster.Prophet at 0x7fbd7df26070>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = prophet.Prophet(yearly_seasonality=True, weekly_seasonality=True, seasonality_mode=\"additive\")\n",
    "for name in lag_features:\n",
    "    model.add_regressor(name)\n",
    "\n",
    "model.fit(df=historical_data.iloc[:-1, :].rename(columns={\"Date\": \"ds\", \"Close\":\"y\"}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:53.078712Z",
     "start_time": "2020-08-22T21:56:52.201450Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 94)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "forecast = model.predict(\n",
    "    historical_data.iloc[-1:][[col for col in historical_data.columns if col != \"Close\"]].rename(columns={\"Date\": \"ds\"})\n",
    ")\n",
    "\n",
    "forecast.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-22T21:56:53.083700Z",
     "start_time": "2020-08-22T21:56:53.081146Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1564.282633\n",
       "Name: yhat, dtype: float64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "forecast.yhat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:dlX]",
   "language": "python",
   "name": "conda-env-dlX-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
